"""
@author: LiuJun
@file: 玩家对战.py
@time: 2022/12/2 16:09
"""
class Player:
    def __init__(self, name, sex, HP, equip, room):
        self.name = name
        self.sex = sex
        self.HP = HP
        self.equip = equip
        self.room = room
    def fight(self,player):
        if player.equip == 1:
            player.HP -= 5
        if player.equip == 0:
            player.HP -= 10

class Room:
    def __init__(self, room_number, room_player1, room_player2):
        self.room_number = room_number
        self.room_player1 = room_player1
        self.room_player1 = room_player1


players = {}
rooms = {}
player0 = Player("zero", "man", 100, 1, 0)
player1 = Player("one", "man", 100, 0, 0)
players[player1.name] = player1
players[player0.name] = player0
while 1:
    print("1.选择角色\n2.创建角色")
    op = input("请输入你的选择：")
    if op == "q":
        break
    if op == "1":
        while 1:
            print("已存在以下角色：")
            for i in players:
                print(i)
            name1 = input("请输入第一个角色名(q返回)：")
            if name1 == "q":
                break
            name2 = input("请输入第二个角色名(q返回)：")
            if name1 == "q":
                break
            print("已存在以下房间：")
            for i in rooms:
                print(i)
            print("请创建对战房间：")
            num = input("请输入房间号(q返回)：")
            if num == "q":
                break
            room = Room(num, name1, name2)
            if num in rooms:
                print("房间已存在")
            else:
                rooms[room.room_number] = room
                print('**开始战斗**')
                i = 0
                while 1:
                    i += 1
                    print(f"{name1}砍了{name2}一刀")
                    players[name2].fight(players[name2])
                    print(f"{name2}砍了{name1}一刀")
                    players[name1].fight(players[name1])
                    print(f"{name1}--HP:{players[name1].HP}---{name2}--HP:{players[name2].HP}")
                    if players[name1].HP <= 0 and players[name2].HP <= 0:
                        print("同归于尽")
                        break
                    elif players[name1].HP <= 0:
                        print(f"{name2}获得胜利")
                        break
                    elif players[name2].HP <= 0:
                        print(f"{name1}获得胜利")
                        break
    if op == "2":
        name = input("请输入角色名：")
        sex = input("请输入性别(man or woman)：")
        equip = input("请选择装备数量(0或1)：")
        player = Player(name,sex,100,equip,0)
        players[name] = player
    else:
        print("输入不合法")
